package com.mxf.code.product_coupon.enums;

import lombok.Getter;

import java.math.BigDecimal;
import java.util.stream.Stream;

/**
 * @author mxf
 * @version 1.0
 * @description: 会员等级枚举
 * @date 2023/6/9
 */
@Getter
public enum MemberDiscountEnum {
    /**
     * 非会员
     */
    NON_MEMBER(Integer.MIN_VALUE, new BigDecimal("1")),
    /**
     * 一级会员
     */
    DISCOUNT_RATE_LEVEL1(1, new BigDecimal("0.9")),
    /**
     * 二级会员
     */
    DISCOUNT_RATE_LEVEL2(2, new BigDecimal("0.85")),
    /**
     * 三级会员
     */
    DISCOUNT_RATE_LEVEL3(3, new BigDecimal("0.8"));
    private final Integer level;
    private final BigDecimal discount;

    MemberDiscountEnum(Integer level, BigDecimal discount) {
        this.level = level;
        this.discount = discount;
    }

    public static BigDecimal getDiscountByLevel(Integer level) {
        return Stream.of(MemberDiscountEnum.values())
                .filter(e -> e.getLevel().equals(level))
                .map(MemberDiscountEnum::getDiscount)
                .findFirst().orElse(new BigDecimal("1"));
    }
}
